package com.ssm.controller;

import com.ssm.entity.TbSpecification;
import com.ssm.service.TbSpecificationService;
import com.ssm.SpecificationDto;
import com.ssm.utils.PageResult;
import com.ssm.utils.R;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/specification")
public class TbSpecificationController {
    private final TbSpecificationService tbSpecificationService;

    public TbSpecificationController(TbSpecificationService tbSpecificationService) {
        this.tbSpecificationService = tbSpecificationService;
    }

    @PostMapping("/conditionFindByPage")
    public PageResult<TbSpecification> conditionFindByPage(Integer page, Integer pageSize, @RequestBody TbSpecification specification){
        return tbSpecificationService.conditionFindByPage(page,pageSize,specification.getSpecName());
    }
    @PostMapping("/addTbSpecification")
    public R addTbSpecification(@RequestBody SpecificationDto specificationDto){
        try{
            tbSpecificationService.addTbSpecification(specificationDto);
        }catch (Exception e){
            e.printStackTrace();
            return R.error().message("添加失败!");
        }
        return R.ok().message("添加成功!");
    }
}
